﻿
@page "/Bas/Goods/Create"
@using nERP.ViewModel.Bas.GoodsVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
  <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit" >
    <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
      <BootstrapInput @bind-Value="@Model.Entity.GoodsCode"/>
      <BootstrapInput @bind-Value="@Model.Entity.GoodsName"/>
      <BootstrapInput @bind-Value="@Model.Entity.GoodsSpec"/>
      <Select @bind-Value="@Model.Entity.GoodsTypeId" Items="AllGoodsTypes" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
      <Select @bind-Value="@Model.Entity.GoodsUnitId" Items="AllGoodsUnits" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" IsPopover ShowSearch />
      <BootstrapInput @bind-Value="@Model.Entity.RestockingPrice"/>
      <BootstrapInput @bind-Value="@Model.Entity.RetailPrice"/>
      <BootstrapInput @bind-Value="@Model.Entity.WholesalePrice"/>
      <BootstrapInput @bind-Value="@Model.Entity.SafetyStock"/>
      <BootstrapInput @bind-Value="@Model.Entity.Remark"/>
      <WTUploadImage @bind-Value="@Model.Entity.GoodsImages"/>
    </Row>

    <div class="modal-footer table-modal-footer">
      <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]"/>
      <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]"/>
    </div>

  </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private GoodsVM Model = new GoodsVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {
                        
        
        await PostsForm(vform, "/api/Bas/Goods/Create", (s) => "Sys.OprationSuccess");
    }
    public void OnClose()
    {
        CloseDialog();
    }
    
    private List<SelectedItem> AllGoodsTypes = new List<SelectedItem>();
    private List<SelectedItem> AllGoodsUnits = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {
        
        
        AllGoodsTypes = await WtmBlazor.Api.CallItemsApi("/api/Bas/Goods/GetGoodsClasss");
        AllGoodsTypes.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        AllGoodsUnits = await WtmBlazor.Api.CallItemsApi("/api/Bas/Goods/GetComputationUnits");
        AllGoodsUnits.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });

        await base.OnInitializedAsync();
    }
}
